<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>useState优先级</title>
  </head>
  <body>
    <div id="root"></div>
    <script src="../../libs/babel.min.js"></script>
    <script src="../../libs/react-17.0.2.js"></script>
    <script src="../../libs/react-dom-17.0.2.js"></script>
    <script type="text/babel">
      const App = props => {
        // 添加一个 hook
        const [num, setNum] = React.useState("0")

        const handleClickBtn = () => {
          console.log("handleClickBtn")
          setNum(num2 => num2 + "2")
        }

        const handleClickNumberBtn = () => {
          setNum(10)
        }

        React.useEffect(() => {
          setNum(num3 => num3 + "3")
          // 低优先级任务 - AUpate
          setTimeout(() => setNum(num1 => num1 + "1"), 1000)
          // 高优先级任务 - BUpdate
          setTimeout(() => document.getElementById("btn1").click(), 1040)

          for (let index = 0; index < 10000000000; index++) {
            const element = index
          }
        }, [])

        return (
          <div>
            <button id="btn1" onClick={handleClickBtn}>
              切换 -
            </button>
            <button onClick={handleClickNumberBtn}>切换Num - {num}</button>
          </div>
        )
      }
      const root = document.getElementById("root")
      ReactDOM.render(<App app={1} />, root)
    </script>
  </body>
</html>
